package Thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Demo31 {
    public static void main(String[] args) {
        ExecutorService threadPool = Executors.newFixedThreadPool(6);
        //ExecutorService threadPool1 = Executors.newCachedThreadPool();
        for(int i =0;i<1000;i++){
            int id = i;
            threadPool.submit(()->{
                System.out.println("hello"+id+"," + Thread.currentThread().getName());
            });
        }
        //shutdown 能够把线程池里的线程全部关闭，但是不能保证线程池内的任务一定能全部执行完毕。
        //所以，如果需要等待线程池内的任务全部执行完毕，需要调用 awaitTermination方法.
        threadPool.shutdown();
    }

}
